package com.note7_5;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.Scanner;

public class Question5 {

	/*
	 * 通过控制台输入字符，如果输入的是quit,则退出,否则继续输入;把输入的字符写入文件保存。
	 */
	
	public static void main(String[] args) {
		OutputStream os = null;
		try {
			os = new FileOutputStream("D:/myeclipse/workpace/com/src/com/stu7_5/question5.txt");
			Scanner in = new Scanner(System.in);
			System.out.println("请输入文件内容：");
			while(true){
				String input = in.nextLine();
				if(!input.equals("quit")){
					os.write(input.getBytes("GBK"));
				}else{
					break;
				}
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
			if(os != null){
				try {
					os.close();
				} catch (IOException e) {
					System.out.println("输出流关闭失败");
					e.printStackTrace();
				}
			}
		}
	}
}
